<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<%@ include file="/common/meta.jsp"%>
<script type="text/javascript">
	BUI.use('common/page');
</script>
</head>

<body>

	<div class="place">
		<span>位置：</span>
		<ul class="placeul">
			<li><a href="/ms">首页</a></li>
			<li><a href="/ms/docIdentity">档号标识</a></li>
		</ul>
	</div>
	<div id="content" class="hide">
		<form class="well form-inline">
			<div class="row">
				<div class="control-group span8">
					<label class="control-label"><s>*</s>序号：</label>
					<div class="controls">
						<input name="seq" type="text" class="input-normal" />
					</div>
				</div>
				<div class="control-group span10">
					<label class="control-label"><s>*</s>分类号：</label>
					<div class="controls">
						<select name="item" class="input-normal">
							<option value="">请选择</option>
							<option value="CZ">全宗号</option>
							<option value="DL">大类号</option>
							<option value="GD">归档年度</option>
							<option value="QX">保存期限</option>
							<option value="LX">流水号</option>
						</select>
					</div>
				</div>
				<div class="control-group span10">
					<label class="control-label"><s>*</s>长度：</label>
					<div class="controls">
						<select name="length" class="input-normal">
							<option value="">请选择</option>
							<option value="4">4</option>
							<option value="8">8</option>
							<option value="12">12</option>
						</select>
					</div>
				</div>
				<div class="control-group span10">
					<label class="control-label"><s>*</s>分隔符：</label>
					<div class="controls">
						<select name="split" class="input-normal">
							<option value="">请选择</option>
							<option value="-">-</option>
							<option value="*">*</option>
							<option value="@">@</option>
							<option value="#">#</option>
						</select>
					</div>
				</div>				
			</div>
		</form>
	</div>

	<div id="grid"></div>
	<div id="text">
		<p id="selecttext"></p>
	</div>
	<script type="text/javascript">
		BUI.use([ 'bui/grid', 'bui/data' ], function(Grid, Data) {

			var columns = [{
				title : '顺序',
				dataIndex : 'seq',
				width : '8%'
			}, {
				title : '档号组成项',
				dataIndex : 'item',
				width : '20%'
			}, {
				title : '长度',
				dataIndex : 'length',
				width : '10%'
			}, {
				title : '分隔符',
				dataIndex : 'split',
				width : '10%'
			} , {
				title : '操作',
				dataIndex : 'd',
				width : '12%',
				renderer : function(value, obj) {
					return '<span class="grid-command btn-edit">编辑</span>';
				}
			} ],

			store = new Data.Store({
				url : '/ms/docIdentity/docIdentityList',
				autoLoad : true, //自动加载数据
				//params : { //配置初始请求的参数
				//  a : 'a1',
				// b : 'b1'
				//},
				pageSize : 5
			// 配置分页数目
			});

			var editing = new Grid.Plugins.DialogEditing({
				contentId : 'content',//弹出框显示的内容的id
				triggerCls : 'btn-edit' ,//点击表格行时触发编辑的 css				
		        editor : {
		                title : '编辑信息',
		                width : 500,
		        }
			});

			grid = new Grid.Grid({
				render : '#grid',
				width : '100%',//如果表格使用百分比，这个属性一定要设置
				columns : columns,
				loadMask : true, //加载数据时显示屏蔽层
				store : store,
				plugins : [ Grid.Plugins.AutoFit ],
				plugins : [ Grid.Plugins.CheckSelection, editing ],
				//plugins : [Grid.Plugins.CheckSelection,Grid.Plugins.ColumnResize],
				// 底部工具栏
				bbar : {
					// pagingBar:表明包含分页栏
					pagingBar : true
				},
				tbar : {
					items : [ {
						btnCls : 'button',
						text : "<i class='icon-plus'></i>添加",
						listeners : {
							'click' : addFunction
						}
					}, {
						btnCls : 'button',
						text : "<i class='icon-minus'></i>删除",
						listeners : {
							'click' : delFunction
						}
					} ]
				}
			});

			grid.render();

			function addFunction() {
				var newData = {};
				editing.add(newData); //直接弹出框编辑
			}
			function delFunction() {
				var selections = grid.getSelection();//获取表格选择的数据行
				if (!selections || selections.length <= 0) {
					BUI.Message.Alert("请选择要删除数据项，可多选", "warning");
					return;
				}
				BUI.Message.Confirm('确认删除么？', function() {
					var ids = {};//批量删除的数组ID
					for (var i = 0; i < selections.length; i++) {
						ids[i] = selections[i].id;
					}
					$.post("/ms/docIdentity/deleteBatch", {
						ids : ids
					}, function(data, status) {

						if (data.success) {
							store.remove(selections);//删除成功重载grid表格数据
						} else {
							BUI.Message.Alert("删除错误", "error");
						}
					});
				}, 'question');
				return false;
			}
			;
		});
	</script>
</body>

</html>
